package cn.lan.scau_hotel_service.service.impl;

import cn.lan.scau_hotel_service.entity.Hotel;
import cn.lan.scau_hotel_service.repository.HotelRepository;
import cn.lan.scau_hotel_service.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;


@Service
public class HotelServiceImpl implements HotelService {


    @Autowired
    private HotelRepository hotelRepository;

    @Override
    public Hotel getHotelById(int id) {
        return hotelRepository.getHotelById(id);
    }

    @Override
    public Hotel getHotelByName(String name) {
        return hotelRepository.getHotelByLocaName(name);
    }

    @Override
    public boolean saveHotel(Hotel hotel) {
        return hotelRepository.save(hotel)!=null;
    }

    @Override
    @Transactional
    public boolean deleteHotelById(int id) {
        return hotelRepository.deleteHotelById(id)!=0;
    }

    @Override
    public List<Hotel> findAll() {
        return hotelRepository.findAll();
    }
}
